package com.xialinrui.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xialinrui.dto.TodoDto;
import com.xialinrui.entity.Affair;
import com.xialinrui.mapper.AffairMapper;
import com.xialinrui.service.AffairService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author xialinrui
 */
@Service
public class AffairServiceImpl extends ServiceImpl<AffairMapper, Affair> implements AffairService {


    @Resource
    private AffairMapper affairMapper;

    @Override
    public void addOneAffair(Affair affair) {
        affairMapper.insert(affair);
    }

    @Override
    public void addTodoToAffair(Long affairId, Long todoId) {
        affairMapper.addTodoToAffair(affairId, todoId);
    }

    @Override
    public void deleteAffair(Long affairId, Long todoId) {
        affairMapper.deleteAffair(affairId, todoId);
    }

    @Override
    public List<TodoDto> selectAllTodosByAffairId(Long affairId) {
        return affairMapper.selectAllTodosByAffairId(affairId);
    }

    @Override
    public void deleteAffairById(Long affairId) {
        QueryWrapper<Affair> affairQueryWrapper = new QueryWrapper<>();
        affairQueryWrapper.eq("id", affairId);
        affairMapper.delete(affairQueryWrapper);
    }
}
